/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucm;

import java.sql.ResultSet;
import model.DomeMainView_Model;
import sql.SELECT_SQL;
import view.DomeMain_View;

/**
 *
 * @author 马凯
 */
public class ChangeDomeNo_UC {

    private static ChangeDomeNo_UC cdn;
    private DomeMainView_Model dmvm;
    private DomeMain_View dmv;
    private String buildingNo;
    private String floorNo;
    private String domeNo;

    public static ChangeDomeNo_UC getInstance(DomeMain_View dmv) {
        if (cdn == null) {
            cdn = new ChangeDomeNo_UC();
            cdn.dmv = dmv;
            cdn.dmvm = dmv.getViewModel();
        }
        return cdn;
    }

    public void run() {
        domeNo = String.valueOf(this.dmvm.getFloor_CB().getSelectedIndex() + 1) + "01";
        buildingNo = String.valueOf(this.dmvm.getBuilding_CB().getSelectedIndex() + 1);
        this.dmvm.getDomeNo_TF().setText(domeNo);
        String query = "SELECT * FROM dormitory WHERE apartment='" + buildingNo + "' and room='" + domeNo + "';";
        ResultSet rs = SELECT_SQL.getInstance().run(query);
        try {
            if (rs.first()) {
                this.dmvm.getCheckPicture_La().setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\马凯\\My Documents\\ok.jpg"));
            }else{
                this.dmvm.getCheckPicture_La().setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\马凯\\My Documents\\denied.jpg"));
            }
        } catch (Exception e) {

        }

    }
}
